class NetDev
  @@net_dev_counter_names = %w{
    recv_bytes
    recv_packets
    recv_errs
    recv_drop
    recv_fifo
    recv_frame
    recv_compressed
    recv_multicast
    xmit_bytes
    xmit_packets
    xmit_errs
    xmit_drop
    xmit_fifo
    xmit_colls
    xmit_carrier
    xmit_compressed
    }
  def initialize()
    @netdev = Hash.new
    netdev = IO.readlines("/proc/net/dev")
    netdev.each do |line|
      next if line =~ /^Inter-/
      next if line =~/^ face/
      (name, data) = line.split(/:/, 2)
      name.strip!
      fields = data.split(' ')
      if (fields.length >= 16)
        @@net_dev_counter_names.each do |counter_name|
          @netdev["#{name}_#{counter_name}"] = fields.shift
        end
      end
    end
  end
end
